package com.atguigu.jdkOnePointEight;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author Guo 2022/9/7 11:00:44
 */
public class streamAndLocalTime {

    public static void main(String[] args) throws InterruptedException {
        List<String> list = Arrays.asList("张三", "李四", "王五", "xuwujing");

        List<String> collect = list.stream().filter(x -> !"李四".equals(x)).collect(Collectors.toList());
        String str1 = list.stream().filter("李四1"::equals).findAny().orElse("找不到啊");
        System.out.println(collect);
        System.out.println(str1);

        Stream<String> stream = Stream.of("a", "b", "c");


        List<String> list3 = Arrays.asList("zhangSan", "liSi", "wangWu");
        System.out.println("转换之前的数据:" + list3);
//        List<String> list4 = list3.stream().map(String::toUpperCase).collect(Collectors.toList());
        List<String> list4 = list3.stream().map(x -> x.toUpperCase()).collect(Collectors.toList());
        System.out.println("转换之后的数据:" + list4);
        // 转换之后的数据:[ZHANGSAN, LISI,WANGWU]


        LocalDateTime ldt = LocalDateTime.now();
        System.out.println(ldt);
        System.out.println("格式化时间: " + ldt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")));
        //格式化时间:2018-12-19 15:37:47.119

        LocalDate ld = LocalDate.parse("2017-11-17");
        LocalDate ld2 = LocalDate.parse("2018-01-05");
        Period p = Period.between(ld, ld2);
        System.out.println("相差年: " + p.getYears() + " 相差月 :" + p.getMonths() + " 相差天:" + p.getDays());
        // 相差年: 0 相差月 :1 相差天:19


        Instant inst1 = Instant.now();
        System.out.println("当前时间戳 : " + inst1);
        Thread.sleep(1000L*5);
        Instant inst2 = Instant.now();
//        Instant inst2 = inst1.plus(Duration.ofSeconds(10));
        System.out.println("增加之后的时间 : " + inst2);
        System.out.println("相差毫秒 : " + Duration.between(inst1, inst2).toMillis());
        System.out.println("相毫秒 : " + Duration.between(inst1, inst2).getSeconds());
        // 当前时间戳 : 2018-12-19T08:14:21.675Z
        // 增加之后的时间 : 2018-12-19T08:14:31.675Z
        // 相差毫秒 : 10000
        // 相毫秒 : 10


    }
}
